﻿using System;
using System.Text;
using NUnit.Framework;
using Evaluant.Uss;
using Evaluant.Uss.ObjectContext;

namespace NUnit.PersistenceManager.SerializeAsAttribute
{

    [TestFixture]
    public class Fixture
    {
        IPersistenceProvider provider = XmlConfigLoader.LoadXmlConfig("engines.config", "Prevalence");
        public Evaluant.Uss.ObjectContext.ObjectContext oc;
        
        public Fixture()
        {
            provider.RegisterMetaData(MetaDataFactory.FromAssembly(typeof(Person).Assembly));
            provider.RegisterMetaData(MetaDataFactory.FromMetaDataFile(@"..\..\PersistenceManager\SerializeAsAttribute\Metadata.xml"));

            provider.InitializeConfiguration();

            ObjectService os = new ObjectService(provider);
            oc = os.CreateObjectContext();
        }

        public virtual void ShouldSerializePropertiesAsAttribute()
        {
            oc.InitializeRepository();

            Person p = new Person();
            p.Name = "Erik";
            p.Properties.Add("A");
            p.Properties.Add("B");

            oc.BeginTransaction();
            oc.Serialize(p);
            oc.CommitTransaction();

            oc.Clear();

            p = oc.LoadSingle<Person>();

            Assert.IsNotNull(p);
            Assert.AreEqual("Erik", p.Name);
            Assert.IsNotNull(p.Properties);
            Assert.AreEqual(2, p.Properties.Count);
            Assert.AreEqual("A", p.Properties[0]);
            Assert.AreEqual("B", p.Properties[1]);
 
        }

    }
}
